#include <iostream>
#include "mfile.hpp"
using namespace std;
#define TIMES 4 
int main( int argc , char ** argv ){
	mFile my_file;
	cout << "is_open:"<<my_file.is_open() <<endl;

	my_file.open(argv[1]);
	cout << "is_open:"<<my_file.is_open() <<endl;
	char buf[11];
	memset(buf , 0 ,11);
	int i;
	for( i=0 ;i<TIMES ;i++ ){
		int len = sprintf(buf , "hellohel%02d" , i);
		my_file.write( buf , len );
	}
	int len = sprintf(buf , "hellohel%02d" , i);
	my_file.write( buf , len , MF_OPT_WT_BEG );

	for( i=0 ; i<TIMES ; i++ ){
		memset(buf , 0 ,11);
		cout << "totle bytes:" << my_file.read( buf , 10 ) <<endl;
		cout << "content:"<<buf <<endl;
	}
	cout << "*********************" <<endl;
	for( i=0 ; i<TIMES/2 ; i++ ){
	
		memset(buf , 0 ,11);
		cout << "totle bytes:" << my_file.read( buf , 10 ,MF_OPT_WT_BEG ) <<endl;
		cout << "content:"<<buf <<endl;
		memset(buf , 0 ,11);
		cout << "totle bytes:" << my_file.read( buf , 10 ) <<endl;
		cout << "content:"<<buf <<endl;
	}
//	struct stat status;
//	my_file.stat( &status );

/*	my_file.rename( argv[2]);
	cout << "*********************" <<endl;
	for( i=0 ; i<TIMES/2 ; i++ ){
	
		memset(buf , 0 ,11);
		cout << "totle bytes:" << my_file.read( buf , 10 ,MF_OPT_WT_BEG ) <<endl;
		cout << "content:"<<buf <<endl;
		memset(buf , 0 ,11);
		cout << "totle bytes:" << my_file.read( buf , 10 ) <<endl;
		cout << "content:"<<buf <<endl;
	}
*/
//	my_file.remove();
	my_file.close();
	
	cout << "is_open:"<<my_file.is_open() <<endl;
}
